/**
 * 
 */
package view.impl.menu.items;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.UnicodeFont;

/**
 * @author Julian
 *
 */
public class MenuButton implements IMenuItem {

	private String text;
	private UnicodeFont uFont;
	private int posX;
	private int posY;
	private Color fontColor;
	
	private IMenuArrow arrows;
	
	public MenuButton(String text, UnicodeFont uFont, int posX, int posY) {
		this(new MenuArrow(posX, posY, uFont.getWidth(text), uFont.getHeight(text)), 
			 text, 
			 uFont, 
			 posX, 
			 posY, 
			 new Color(255, 185, 25));
	}
	
	public MenuButton(IMenuArrow arrows, String text, UnicodeFont uFont, int posX, int posY, Color fontColor) {
		this.arrows = arrows;
		this.text = text;
		this.uFont = uFont;
		this.posX = posX;
		this.posY = posY;
		this.fontColor = fontColor;
	}
	
	public void updateFont(UnicodeFont uFont) {
		this.uFont = uFont;
	}

	/* (non-Javadoc)
	 * @see client.view.IMenuItem#draw()
	 */
	@Override
	public void draw(boolean selected, Graphics g, int windowWidth, int windowHeight) {
		uFont.drawString(posX, posY, text, fontColor);
		if(selected) {
			arrows.draw(g, windowWidth, windowHeight);
		}
	}

	/* (non-Javadoc)
	 * @see client.view.IMenuItem#getPosX()
	 */
	@Override
	public int getPosX() {
		return posX - arrows.getWidth() / 2;
	}

	/* (non-Javadoc)
	 * @see client.view.IMenuItem#getPosY()
	 */
	@Override
	public int getPosY() {
		if(arrows.getHeight() < uFont.getHeight(text))
			return posY;
		else
			return posY - (arrows.getHeight() - uFont.getHeight(text)) / 2;
	}

	/* (non-Javadoc)
	 * @see client.view.IMenuItem#getWidth()
	 */
	@Override
	public int getWidth() {
		return uFont.getWidth(text) + arrows.getWidth();
	}

	/* (non-Javadoc)
	 * @see client.view.IMenuItem#getHeight()
	 */
	@Override
	public int getHeight() {
		if(arrows.getHeight() < uFont.getHeight(text)) {
			return uFont.getHeight(text);
		}
		else {
			return arrows.getHeight();
		}
	}
	
	@Override
	public void move(int deltaX, int deltaY) {
		posX += deltaX;
		posY += deltaY;
		arrows.move(deltaX, deltaY);
	}
	
	@Override
	public void setPos(int posX, int posY) {
		this.posX = posX;
		this.posY = posY;
		arrows.setPosition(posX, posY);
	}
}
